package cn.jia.hrm.context;

import cn.jia.hrm.domain.LoginUser;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class LoginUserContext {

    public static LoginUser loginUser(){
        SecurityContext context = SecurityContextHolder.getContext();
        /*if(context == null){
            return null;
        }*/

        Authentication authentication = context.getAuthentication();

        /*if(authentication == null){
            return null;
        }*/

        String principal = (String)authentication.getPrincipal();
        LoginUser loginUser = JSON.parseObject(principal,LoginUser.class);
        return  loginUser;
    }
}
